'----------------------------
'- 0x0000..0x17FF
'- 6kb
'----------------------------

asm
  ld sp,$1FFF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"
#include "./library/astinvadldirxor.bas"
#include "./library/b1r1f1_charmapbeaminvader01.zxi"

sub dorachanputchar(txp1 as uinteger,typ1 as uinteger, tch1 as uinteger,tlc1 as uinteger,txor1 as ubyte):
  astinvadldirxor($4000+((typ1 bxor 31)*256)+(txp1*8),tlc1+((tch1 band $FF)*8),8,txor1)
  end sub


dim eee as uinteger at $1810
dim seed as uinteger at $1812
dim ee0 as uinteger at $1814
dim ee1 as uinteger at $1816
dim ee2 as uinteger at $1818
dim ee3 as uinteger at $181A
dim eex as uinteger at $181C
dim eey as uinteger at $181E

seed=0


for ee2=0 to 31
  for ee3=0 to 31
    seed=smsrnd(seed) 
    dorachanputchar(ee3,ee2,96+(seed mod 9),@charmap01,$FF)
    pacmandelay(500)
    next:next

for ee2=0 to 7
  for ee3=0 to 15
    dorachanputchar(ee3+14,ee2+14,(ee2*16)+ee3,@charmap01,$FF)
    dorachanputchar(ee3+14,ee2+22,(ee2*16)+ee3,@charmap01,$00)
    pacmandelay(500)
    next:next

eex=8:eey=8
eee=0
do

dorachanputchar(2,2,48+(int(eee/100) mod 10),@charmap01,$FF)
dorachanputchar(3,2,48+(int(eee/10) mod 10),@charmap01,$FF)
dorachanputchar(4,2,48+(eee mod 10),@charmap01,$FF)

ee0=peek($2800) bxor $FF
dorachanputchar(2,4,48+(int(ee0/100) mod 10),@charmap01,$FF)
dorachanputchar(3,4,48+(int(ee0/10) mod 10),@charmap01,$FF)
dorachanputchar(4,4,48+(ee0 mod 10),@charmap01,$FF)

ee0=peek($2C00) bxor $FF
dorachanputchar(2,5,48+(int(ee0/100) mod 10),@charmap01,$FF)
dorachanputchar(3,5,48+(int(ee0/10) mod 10),@charmap01,$FF)
dorachanputchar(4,5,48+(ee0 mod 10),@charmap01,$FF)

eex=eex-((ee0 band 64)/64)+((ee0 band 128)/128)
eey=eey+((ee0 band 16)/16)-((ee0 band 32)/32)


dorachanputchar(eex mod 32,eey mod 32,eee mod 128,@charmap01,$FF)

eee=eee+1
loop


do

for eee=$4100 to $5EFF step 8
  for ee0=0 to 7
    seed=smsrnd(seed)
    poke (eee+ee0) bxor %0001111100000000,seed
    next
  pacmandelay(10000)
  next

loop

do:loop







goto codepart2:
'----------------------------
'- 0x2000..0x23FF
asm
org $2000
end asm
'- 1kb
'----------------------------
codepart2:







goto codepart3:
'----------------------------
'- 0x6000..0x77FF
asm
org $6000
end asm
'- 6kb
'----------------------------
codepart3:







'- static ADDRESS_MAP_START( dorachan_map, AS_PROGRAM, 8, dorachan_state )
'- AM_RANGE(0x0000, 0x17ff) AM_ROM
'- AM_RANGE(0x1800, 0x1fff) AM_RAM
'- AM_RANGE(0x2000, 0x23ff) AM_ROM
'- AM_RANGE(0x2400, 0x2400) AM_MIRROR(0x03ff) AM_READ_PORT("PROT")
'- AM_RANGE(0x2800, 0x2800) AM_MIRROR(0x03ff) AM_READ_PORT("SYSTEM")
'- AM_RANGE(0x2c00, 0x2c00) AM_MIRROR(0x03ff) AM_READ_PORT("JOY")
'- AM_RANGE(0x3800, 0x3800) AM_MIRROR(0x03ff) AM_READ_PORT("V128")
'- AM_RANGE(0x4000, 0x5fff) AM_RAM AM_SHARE("videoram")
'- AM_RANGE(0x6000, 0x77ff) AM_ROM
'- ADDRESS_MAP_END






